/**
 * 
 * Copyright (C) 2011 Cody Stoutenburg . All rights reserved.
 *
 *       This program is free software; you can redistribute it and/or
 *       modify it under the terms of the GNU Lesser General Public License
 *       as published by the Free Software Foundation; either version 2.1
 *       of the License, or (at your option) any later version.
 *
 *       This program is distributed in the hope that it will be useful,
 *       but WITHOUT ANY WARRANTY; without even the implied warranty of
 *       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *       GNU Lesser General Public License for more details.
 *
 *       You should have received a copy of the GNU Lesser General Public License
 *       along with this program; if not, write to the Free Software
 *       Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. 
 * 
 */
package ca.usherbrooke.builder.feature;

import ca.usherbrooke.application.MyTiledMap;
import ca.usherbrooke.model.damage.ConstantDamage;
import ca.usherbrooke.model.damage.Damage;
import ca.usherbrooke.model.damage.NullDamage;
import ca.usherbrooke.model.damage.RandomDamage;

/**
 * @author Cody Stoutenburg
 * 
 */
public class DamageModelBuilder {
	private static final String TILE_PROPERTY_DAMAGE_TYPE = "damage.type";

	private static final String TILE_PROPERTY_VALUE_NULL_DAMAGE = "null";
	private static final String TILE_PROPERTY_VALUE_RANDOM_DAMAGE = "random";
	private static final String TILE_PROPERTY_VALUE_CONSTANT_DAMAGE = "constant";

	private static final String TILE_PROPERTY_DAMAGE_DICE_COUNT = "damage.random.count";
	private static final String TILE_PROPERTY_DAMAGE_DICE_VALUE = "damage.random.value";

	private static final String TILE_PROPERTY_DAMAGE_VALUE = "damage.constant.value";

	private static final Integer DEFAULT_VALUE_DICE_COUNT = 1;
	private static final Integer DEFAULT_VALUE_DICE_VALUE = 6;
	private static final Integer DEFAULT_VALUE_DAMAGE = 1;
	private static final String DEFAULT_VALUE_DAMAGE_TYPE = TILE_PROPERTY_VALUE_NULL_DAMAGE;

	public static Damage generateDamage(MyTiledMap tmap, int tid) {
		Damage damage = null;
		String damageType = tmap.getTileProperty(tid,
				TILE_PROPERTY_DAMAGE_TYPE, DEFAULT_VALUE_DAMAGE_TYPE);

		if (TILE_PROPERTY_VALUE_NULL_DAMAGE.equals(damageType)) {
			damage = new NullDamage();
		} else if (TILE_PROPERTY_VALUE_RANDOM_DAMAGE.equals(damageType)) {
			int diceCount = ModelBuilderTools.getTileProperty(tmap, tid,
					TILE_PROPERTY_DAMAGE_DICE_COUNT, DEFAULT_VALUE_DICE_COUNT);
			int dice = ModelBuilderTools.getTileProperty(tmap, tid,
					TILE_PROPERTY_DAMAGE_DICE_VALUE, DEFAULT_VALUE_DICE_VALUE);
			damage = new RandomDamage(diceCount, dice);
		} else if (TILE_PROPERTY_VALUE_CONSTANT_DAMAGE.equals(damageType)) {
			int damageValue = ModelBuilderTools.getTileProperty(tmap, tid,
					TILE_PROPERTY_DAMAGE_VALUE, DEFAULT_VALUE_DAMAGE);
			damage = new ConstantDamage(damageValue);
		}
		return damage;
	}
}
